const personinfo = {
    name:'Personinfo',
    template: `<div class="h100 bg ovy" _class="showMore?'':'h100 bg'">
        <div class="h100 bg" _class="showMore?'disn':'h100 bg'">
            <div class=" flex title fs18 h45 lh45 pr c30 sp2 marb5 bgf">
                <div class=" ffh pdlr20 fs22 fsw1 " @click="$router.go(-1)"><i class="el-icon-back "></i></div>
                <div class="" v-text="ob['用户名']"></div>
            </div>
            <div class="pd010">
            	<div class="h10"></div>
            	<div class="pd015 _mrlr20 pdtb10 bgf br10">
	                <div class="bgf pr flex br10">
	                    <div class="w030 h80 pr">
	                    	<div class="h3"></div>
	                    	<img :src="img" @error="doError()" class="h80 w80  br50 lrm bd1e">
	                    </div>
	                    <div class="w066 lh20 pd010">
	                        <div class="flex jusb textc pd010 fs12">
	                            <div>
	                                <div class="fsw7" v-text="ob['积分']"></div>
	                                <div class="c60">积分</div>
	                            </div>
	                            <div>
	                                <div class="fsw7" v-text="obd.user_id">ID</div>
	                                <div class="c60">ID</div>
	                            </div>
	                            <div>
	                                <div class="fsw7" v-text="ob['血压']"></div>
	                                <div class="c60">血压</div>
	                            </div>
	                            <!--<div>
	                                <div class="fsw7" v-text="ob['血糖']"></div>
	                                <div class="c60">血糖</div>
	                            </div>-->
	                        </div>
	                        <div class="h8"></div>
	                        <div class="bd15f textc  lh30 h30 fs13 br20 c30" @click="opChange()"><span class="">编辑信息</span></div>
	                    </div>
	                </div>
	            </div>
	            <div class="h20"></div>
	            <div class=" br10 mar20_ bgf pd015 pd10">
	            	<div name="baseInfo" class="bgf br10" v-if="showRegister">
	            		<div class="pdl10 marb10 fs17 fsw4 sp2 bb1a lh30">
	            			<span>完成注册</span>
	            		</div>
		                <div>
		                	<div name="attr-item"  class=" textl  bd1c_">
			                    <div class="pd10 mask1">
			                    	<div>
			                    		<span class="" >手机号码</span>
			                        	<span class="pd05">:</span>
			                    	</div>
			                        <div class="bgf bd1c br2 bbx ofh mart5 w100 flex">
			                        	<input type="number" class="bbx w100 lh25 fs15 bdn pd05"  v-model="userPhone"  />
						            </div>
			                    </div>
			                </div>
			                <div name="attr-item"  class=" textl  ">
			                    <div class="pd10 mask1">
			                    	<div>
			                    		<span class="" >身份证号</span>
			                        	<span class="pd05">:</span>
			                    	</div>
			                        <div class="bgf bd1c br2 bbx ofh mart5 w100 flex">
			                        	<input type="text" class="bbx w100 lh25 fs15 bdn pd05"  v-model="userIdcard"  />
						            </div>
			                    </div>
			                </div>
		                </div>
		                <div class="pd010 mart20">
		                	<div class="fs14 btn center bgcg h40 br5 cfff sp5" style="background:#07c160;" @click="doRegist()">
			                	<span>注册</span>
			                </div>
		                </div>
	            	</div>
	            	<div name="baseInfo" class="bgf br10" v-else>
	            		<div class="pd05 marb10 fs17 fsw4 sp2 bb1a lh30">
	            			<span>基本信息</span>
	            		</div>
		                <div v-if="!showMore" class="pd05 bbx">
		                	<!--<div vv-for="(v,k,i) in ob" vv-if="i>4&&i<9" class=" flex textl  ">
			                    <div class="pd10 mask1">
			                        <span class=""  >性别</span>
			                        <span class="pdlr10">:</span>
			                        <span class="" v-text="obd.sex"></span>
			                    </div>
			                </div>-->
		                	<div  class="pdtb10 flex textl  ">
			                    <div class=" mask1">
			                        <span class=""  >姓名</span>
			                        <span class="pd05">:</span>
			                        <span class="" v-text="obd.username"></span>
			                    </div>
			                </div>
			                <div  class="pdtb10 flex textl  ">
			                    <div class=" mask1">
			                        <span class=""  >性别</span>
			                        <span class="pd05">:</span>
			                        <span class="" v-if="obd.sex == 1" >男</span>
			                        <span class="" v-else="obd.sex == 2" >女</span>
			                        <span class="" v-else >其他</span>
			                    </div>
			                </div>
			                <div  class="pdtb10 flex textl  ">
			                    <div class=" mask1">
			                        <span class=""  >体重</span>
			                        <span class="pd05">:</span>
			                        <span class="" v-text="obd.weight"></span>
			                    </div>
			                </div>
			                <div  class="pdtb10 flex textl  ">
			                    <div class=" mask1">
			                        <span class=""  >电话</span>
			                        <span class="pd05">:</span>
			                        <span class="" v-text="obd.phone"></span>
			                    </div>
			                </div>
		                </div>
		                <div v-else>
		                	<div class=" bbx">
				                <div class="pdtb5 pdlr10 bgf7">
				                	<div v-for="(v,k,i) in ob" v-if="i>4&&k!='爱好'" class=" flex textl  ">
					                    <div class="c60 fs13 pd5 bbx ">
					                        <span class="" v-text="k" ></span>
					                        <span class="pdlr10">:</span>
					                        <span class="" v-text="v==''?'未填写':v"></span>
					                    </div>
					                </div>
				                </div>
				                <div class="mart10">
				                    <div class="pd05 marb10 fs17 fsw4 sp2 bb1c lh30">个人介绍</div>
				                    <div class="c60 fs13 pd5 bbx pdtb10 bgf7" >
				                    	<div v-text="ob['爱好']==''?'还没有写个人介绍':ob['爱好']"></div>
				                    </div>
				                </div>
				            </div>
		                </div>
		                <div class="fs13 mask1 textc pdt15 pdb5 bbx  bdt01m" @click="switchMore()">
		                	<div v-if="!showMore">
		                		<span>详细信息</span>
		                		<i class="el-icon-arrow-right"></i>
		                	</div>
		                	<div v-else>
		                		<span>收起</span>
		                		<i class="el-icon-arrow-up"></i>
		                	</div>
		                </div>
		                
		                
	            	</div>
	            	<div class="h10 "></div>
		            
	            </div>
            </div>
            <div class="pd010">
            	<div class="h10"></div>
            	<div v-if="!showRegister" class="fs13 h50 br10 bgf flec center bbx pdtb5 pd010" @click="logout()">
		                	<div class="cr">
		                		<span>注销账号</span>
		        </div>
            </div>
            
		    </div>
        </div>
        <div class="disn" :class="showMore?'h100':'disn'">
            <div class="bgf flex title fs18 h45 lh45 pr c30 sp2 marb5 ">
                <div class=" ffh pdlr20 fs22 fsw1 " @click="switchMore()"><i class="el-icon-back "></i></div>
                <div class="" >基本信息</div>
            </div>
            <div class="pdlr20 bbx">
                <div class="pdtb20 fs15 ff1">个人信息</div>
                <div v-for="(v,k,i) in ob" v-if="i>4&&k!='爱好'" class=" flex textl  ">
                    <div class="c60 fs13 pd5 bbx ">
                        <span class="" v-text="k" ></span>
                        <span class="pdlr10">:</span>
                        <span class="" v-text="v==''?'未填写':v"></span>
                    </div>
                </div>
                <div class="h10"></div>
                <div>
                    <div class="pdtb20 fs15 ff1">个人介绍</div>
                    <div class="c60 fs13 pd5 bbx " v-text="ob['爱好']==''?'还没有写个人介绍':ob['爱好']"></div>
                </div>
            </div>

        </div>
        </div>
    `,
    data: function () { return{
        ob:{
            // '用户名':"",
            // '头像':"",
            // '积分':"0",
            // id:"",
            // '性别':"",
            // '国家':'中国',
            // '省份':'',
            // '城市':'',
            // '生日':'',
            // '身高':'',
            // '体重':'',
            // '腰围':'',
            // '国家':'',
            // '血压':'0',
            // '血糖':'0',
            // '爱好':'',
        },
        obd: {},
        img:'',
        userPhone: '',
        userIdcard: '',
        hrefA:hrefA,
        showRegister: false,
        showMore:0,
    } },
    created() {
        let v = this
        v.token=localStorage.getItem('token')
        v.getList()
    },
    methods: {
    	switchMore(){
    		let v = this;
    		v.showMore = !v.showMore;
    		console.log('switchMore',v.showMore)
    		if(!v.showMore){
    			v.getList();
    		}
    	},
    	logout(){
    		let v= this
            let uri = '/api/user/delete';
            if(!v.token) return;
            ajax({url:uri,method:'get',data:{token: v.token}}).then((r)=>{
                console.log('r',r);
                localStorage.clear();
                if(r.code == 200){
                	__message('账号已经注销..',3000);
                	localStorage.token = '';
                	setTimeout(function(){
                		v.$router.push({path:'/'});
                	},2000)
                	localStorage.token = '';
                }
            })
    	},
        getList(){
            let v= this
            let uri = '/api/user/info'
            console.log('getList','/api/user/info');
            console.log('token',v.token);
            ajax({url:uri,method:'get',data:{token:v.token}}).then((r)=>{
                console.log('get user info',r);
                if(r.code == 300){
                    console.log('ls',localStorage.token);
                    localStorage.clear();
                    // location.href='http://bsy.5niu.top/api/weixin/login?redirect_url=http://bsy.5niu.top/cuser/admin.html#/personinfo';
                }
                if(r.code == 200){
                    console.log('r.data',r.data);
                    let ob = r.data
                    v.obd = r.data;
                    let o = {}
                    for (const k in ob) {
                        o.user_id = ob['user_id']
                        o['用户名'] = ob['nickname']
                        o['头像'] = ob['avatar']
                        o['积分'] = ob['integral']
                        o['id'] = ob['id']
                        o['性别'] = ob['sex']
                        o['国家'] = ob['country']
                        o['省份'] = ob['province']
                        o['城市'] = ob['city']
                        o['生日'] = ob['birthday']
                        o['身高'] = ob['height']
                        o['体重'] = ob['weight']
                        o['腰围'] = ob['waist']
                        o['血压'] = ob['blood_pressure']
                        o['血糖'] = ob['blood_sugar']
                        o['爱好'] = ob['hobby']
                        o['备注'] = ob['remark']
                        o['电话'] = ob['phone']
                        o['身份证'] = ob['idcard']
                    };
                    v.ob = o
                    v.img = v.ob['头像']
                    if(v.ob['性别'] == '1'){
                        v.ob['性别'] = '男'
                    }else if(v.ob['性别'] == '2'){
                        v.ob['性别'] = '女'
                    }else{
                        v.ob['性别'] = '未知'
                    }
                    console.log('v.ob',v.ob);
                    v.userPhone = ob.phone;
                    v.userIdcard = ob.idcard;
                    if (!v.userPhone || !v.userIdcard){
                    	v.showRegister = true;
                    } else {
                    	v.showRegister = false;
                    }
                    console.log('showRegister',v.showRegister)
                    localStorage.setItem('ob',JSON.stringify(v.ob))
                }
            }).catch((e)=>{
                console.log('catch',e);
            })
            
        },
        doRegist(k,value){
        	let v= this
            let uri = '/api/user/edit'
            let token = '';
            let data= {
            	phone: v.userPhone,
            	idcard: v.userIdcard,
            }
            if(localStorage.getItem('token')){
                token = localStorage.getItem('token')
                data.token = token
            }
            console.log('doRegist',data);
            ajax({url:uri,method:'POST',data:data}).then((r)=>{
                if(r.code == 200){
                    __message('注册成功..',3000,'cg');
                    v.getList();
                } else {
                	__message(r.msg,3000,'cr');
                }
            }).catch((e)=>{
                console.log('catch',e);
            })
        },
        doError(){
            let v=this
            v.img ='http://192.168.0.123:9005/upfile/imgs/e6/a684db00f9e6b5dfc8dad5ea6699ff6f.png'
        },
        opChange(){
            let v = this
            v.$router.push({path:'/changeInfo',query:{ob:JSON.stringify(v.ob)}})
        }
    },
}
export default personinfo